﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test6-5-2.aspx.cs" Inherits="Web_Project.test6_5_2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:mfd_severConnectionString %>" SelectCommand="SELECT Cartoon.ct_id,Cartoon.ct_name,Cartoon.ct_time,Cartoon.ct_au,Cartoon.ct_dq,Cartoon.ct_com,ctCategory.Name,ctCategory.ct_CategoryId FROM ctCategory INNER JOIN Cartoon ON ctCategory.ct_CategoryId = Cartoon.ct_CategoryId" UpdateCommand="UPDATE Cartoon SET ct_id = @ct_id, ct_name = @ct_name, ct_time = @ct_time, ct_dq = @ct_dq, ct_au = @ct_au, ct_com = @ct_com, ct_CategoryId = @ct_CategoryId WHERE (ct_id = @ct_id)">
                <UpdateParameters>
                    <asp:Parameter Name="ct_id" />
                    <asp:Parameter Name="ct_name" />
                    <asp:Parameter Name="ct_time" />
                    <asp:Parameter Name="ct_dq" />
                    <asp:Parameter Name="ct_au" />
                    <asp:Parameter Name="ct_com" />
                    <asp:Parameter Name="ct_CategoryId" />
                </UpdateParameters>
            </asp:SqlDataSource>
            <br />
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ct_id" DataSourceID="SqlDataSource1" >
                <Columns>
                    <asp:TemplateField>
                        <EditItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" OnClientClick="return confirm(&quot;您确定要修改吗？&quot;)" ForeColor="Blue" >修改</asp:LinkButton>
                            &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" ForeColor="Red">取消</asp:LinkButton>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Button ID="Button1" runat="server" CommandName="Edit" Text="编辑" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="ct_id" HeaderText="ct_id" ReadOnly="True" SortExpression="ct_id" />
                    <asp:BoundField DataField="ct_name" HeaderText="ct_name" SortExpression="ct_name" />
                    <asp:TemplateField HeaderText="时间" SortExpression="ct_time">
                        <EditItemTemplate>
                            <asp:Calendar ID="Calendar1" runat="server" SelectedDate='<%# Bind("ct_time") %>'></asp:Calendar>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("ct_time","{0:yyyy/MM/dd}") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="ct_au" HeaderText="ct_au" SortExpression="ct_au" />
                    <asp:BoundField DataField="ct_dq" HeaderText="ct_dq" SortExpression="ct_dq" />
                    <asp:BoundField DataField="ct_com" HeaderText="ct_com" SortExpression="ct_com" />
                    <asp:TemplateField HeaderText="分类">
                        <EditItemTemplate>
                            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:mfd_severConnectionString %>" SelectCommand="SELECT [ct_CategoryId], [Name] FROM [ctCategory]"></asp:SqlDataSource>
                            <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="Name" DataValueField="ct_CategoryId" SelectedValue='<%# Bind("ct_CategoryId") %>'>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            
            <br />
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:mfd_severConnectionString %>" SelectCommand="SELECT Product.ProductId,Product.CategoryId,Product.ListPrice, Product.Image, Category.Name FROM Product INNER JOIN Category ON Product.CategoryId = Category.CategoryId AND Product.CategoryId = Category.CategoryId" UpdateCommand="UPDATE Product SET CategoryId =@CategoryId , ListPrice =@ListPrice , Image =@Image WHERE ProductId=@ProductId">
                <UpdateParameters>
                    <asp:Parameter Name="CategoryId" />
                    <asp:Parameter Name="ListPrice" />
                    <asp:Parameter Name="Image" />
                    <asp:Parameter Name="ProductId" />
                </UpdateParameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:mfd_severConnectionString %>" SelectCommand="SELECT [CategoryId], [Name] FROM [Category]"></asp:SqlDataSource>
            <br />
            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductId" DataSourceID="SqlDataSource3" OnRowUpdating="GridView2_RowUpdating" AllowSorting="True">
                <Columns>
                    <asp:BoundField DataField="ProductId" HeaderText="ProductId" InsertVisible="False" ReadOnly="True" SortExpression="ProductId" >
                    <HeaderStyle ForeColor="Black" />
                    </asp:BoundField>
                    <asp:TemplateField HeaderText="分类" SortExpression="Name">
                        <EditItemTemplate>
                       <asp:RadioButtonList ID="RadioButtonList1" runat="server" 
                            DataSourceID="SqlDataSource4" 
                            DataTextField="Name" 
                            DataValueField="CategoryId"
                            SelectedValue='<%# Bind("CategoryId") %>'>
                        </asp:RadioButtonList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle ForeColor="Black" />
                    </asp:TemplateField>
                    <asp:BoundField DataField="ListPrice" HeaderText="ListPrice" SortExpression="ListPrice" >
                    <HeaderStyle ForeColor="Black" />
                    </asp:BoundField>
                    <asp:TemplateField HeaderText="图片" SortExpression="Image">
                        <EditItemTemplate>
                            <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("Image") %>' />
                            <br />
                            <asp:FileUpload ID="FileUpload1" runat="server" />
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Image") %>' />
                        </ItemTemplate>
                        <HeaderStyle ForeColor="Black" />
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <EditItemTemplate>
                            <asp:Button ID="Button3" runat="server" CommandName="Update" Text="修改" />
                            &nbsp;<asp:Button ID="Button4" runat="server" CommandName="Cancel" Text="取消" />
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Button ID="Button2" runat="server" CommandName="Edit" Text="编辑" />
                        </ItemTemplate>
                        <HeaderStyle ForeColor="Black" />
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            
        </div>
    </form>
</body>
</html>
